// pages/add/childCpns/calculator/calculator.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    valueList: [0,1,2,3,4,5,6,7,8,9, '删除','确认','清空','.'],
    moneyValue: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleClick(e){
      console.log(e.currentTarget.dataset.index)
      const index = e.currentTarget.dataset.index
      if(index === 10){
        console.log('删除')
        let tempValue = this.data.moneyValue
        tempValue = tempValue.substr(0,tempValue.length-1)
        this.setData({
          moneyValue: tempValue
        })
        console.log('删除',tempValue)
        this.triggerEvent('click', { tempValue })
      }else if(index === 11){
        console.log('确认')
        const moneyValue = this.data.moneyValue
        this.triggerEvent('sure',{moneyValue})
      }else if(index === 12){
        console.log('清空')
        this.setData({
          moneyValue: ''
        })
        const tempValue = this.data.moneyValue
        this.triggerEvent('click', { tempValue })
      }else if(index === 13){
        console.log('.')
        let tempValue = this.data.moneyValue
        tempValue += '.'
        this.setData({
          moneyValue: tempValue
        })
        this.triggerEvent('click', { tempValue })
      }else {
        console.log(index)
        let tempValue = this.data.moneyValue
        tempValue += index
        this.setData({
          moneyValue: tempValue
        })
        this.triggerEvent('click', { tempValue})
      }
    }
  }
})
